package com.yc.txx.servlet;

import com.google.gson.Gson;
import com.yc.txx.entity.Car;
import com.yc.txx.mapper.CarMapper;
import com.yc.txx.util.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/FindCarServlet.s")
public class FindCarServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try (SqlSession session = MyBatisHelper.getSession()) {
            CarMapper mapper = session.getMapper(CarMapper.class);
            Car car = mapper.selectById(request.getParameter("id"));
            String json = new Gson().toJson(car);
            response.getWriter().append(json);
        }
    }
}